package com.service.atm;

import com.bpms.common.CommonUtil;
import com.bpms.common.VO;
import com.bpms.eai.PackTool;
import com.bpms.esb.IService;

/**
 * 1002 交易接收 进账单
 * 
 * @author menlin
 * 
 */
public class Parse_atm_into_account extends PackTool implements IService {
	@Override
	public VO exec(VO args) {
		byte[] body = (byte[]) args.getObj("body");
		VO r = new VO();
		r.setAttr("data", args.getAttr("data"));
		try {
			r.voType = "ATM.Answer_atm_into_account";
			String SERIALNO = this.getField(body, body.length, "1000"); // 流水号
//			String DEVICENO = this.getField(body, body.length, "1001"); // 设备号
//			String NETNUM = this.getField(body, body.length, "1002"); // 网点号
//			String 
//			String BillDateTime = this.getField(body, body.length, "1003"); // 日期时间
//			String ACCOUNTTYPE = this.getField(body, body.length, "1004"); // 账号类型  1：ID卡 2：磁条卡 3：身份证
//			String CARDID = this.getField(body, body.length, "1005"); // 账号 ID卡号或磁条卡号或身份证号
//			String PASSWORD = this.getField(body, body.length, "1006"); // 1006  密码
			
			String DEVICENO = this.getField(body, body.length, "1001"); // 设备号  1001
			String NETNUM = this.getField(body, body.length, "1002"); // 网点号  1002
			String CERTNUM = this.getField(body, body.length, "1003"); // 认证码  1003
			String DATETIME = this.getField(body, body.length, "1004"); // 日期时间  1004
			String BILLTYPE = this.getField(body, body.length, "1005"); // 业务类型  01现金支票、02转账支票、04贷记凭证、05电汇凭证  1005
			String LAUNCHSITE = this.getField(body, body.length, "1006"); // 发起网点号
			String SYSTEMTYPE = this.getField(body, body.length, "1014"); // 对应集中处理系统业务类型
			
			String IMGDATA = this.getField(body, body.length, "1019"); // 图码数据
			String IMGNUM = this.getField(body, body.length, "1020"); // 影像张数
			String IMGORDER = this.getField(body, body.length, "1021"); // 影像顺序号（当前上传的为第几张影像）
			// 获取影像字符串
			int imgnum = Integer.parseInt(IMGNUM);
			if (imgnum > 0)
				for (int i = 1; i < (imgnum + 1); i++) {
					if (i < 10)
						r.setAttr("photo" + i,
								getField(body, body.length, "T00" + i));
					if (i >= 10 && i < 100)
						r.setAttr("photo" + i,
								getField(body, body.length, "T0" + i));
					if (i >= 100)
						r.setAttr("photo" + i, getField(body, body.length, "T" + i));
				}


			r.setAttr("SERIALNO", SERIALNO);// 流水号
			r.setAttr("DEVICENO", DEVICENO); // 设备号
			r.setAttr("CERTNUM", CERTNUM); // 认证码  1003
			r.setAttr("NETNUM", NETNUM);
			r.setAttr("DATETIME", DATETIME);
			r.setAttr("BILLTYPE", BILLTYPE);
			r.setAttr("LAUNCHSITE", LAUNCHSITE);
			r.setAttr("SYSTEMTYPE", SYSTEMTYPE);
			r.setAttr("IMGDATA", IMGDATA);
			r.setAttr("IMGNUM", IMGNUM);
			r.setAttr("IMGORDER", IMGORDER);

			CommonUtil.debug("ATM.Parse_atm_into_account parseBuffer");
			return r;
		} catch (Exception e) {
			CommonUtil.debug("ATM.Parse_atm_into_account exception", e);
			return null;
		}
	}

}
